/*
 *    MomentTest.java
 *    Copyright (C) 2011 University of Waikato, Hamilton, New Zealand
 *    @author Maciek Jarka (www.admire-project.eu)
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package moa.associations;

import java.util.ArrayList;
import java.util.List;

import weka.associations.Item;
import weka.associations.NominalItem;
import weka.core.Attribute;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.SparseInstance;

public class MomentTest {

    public static Instance createInstance(double[] values) {
        Instance inst = new SparseInstance(values.length);
        for (int i = 0; i < values.length; i++) {
            inst.setValue(i, values[i]);
        }
        return inst;
    }

    public static void main(String[] args) {
        ArrayList<Attribute> attributes = new ArrayList<Attribute>();
        ArrayList<String> nomVals = new ArrayList<String>();
        Moment associator = new Moment();
        nomVals.add("TRUE");
        nomVals.add("FALSE");


        attributes.add(new Attribute("A", nomVals));
        attributes.add(new Attribute("B", nomVals));
        attributes.add(new Attribute("C", nomVals));
        attributes.add(new Attribute("D", nomVals));
        attributes.add(new Attribute("E", nomVals));
        Instances instances = new Instances("", attributes, 100);

        instances.add(createInstance(new double[]{1, 1, 0, 0, 1}));
        instances.add(createInstance(new double[]{0, 0, 1, 1, 1}));
        instances.add(createInstance(new double[]{0, 0, 0, 1, 1}));
        instances.add(createInstance(new double[]{0, 0, 0, 1, 1}));
        instances.add(createInstance(new double[]{0, 1, 0, 0, 1}));

        instances.add(createInstance(new double[]{1, 1, 0, 0, 1}));
        instances.add(createInstance(new double[]{0, 0, 1, 1, 1}));
        instances.add(createInstance(new double[]{0, 0, 0, 1, 1}));
        instances.add(createInstance(new double[]{0, 0, 0, 1, 1}));
        instances.add(createInstance(new double[]{0, 1, 0, 0, 1}));

        instances.add(createInstance(new double[]{1, 1, 0, 0, 1}));
        instances.add(createInstance(new double[]{0, 0, 1, 1, 1}));
        instances.add(createInstance(new double[]{0, 0, 0, 1, 1}));
        instances.add(createInstance(new double[]{0, 0, 0, 1, 1}));
        instances.add(createInstance(new double[]{0, 1, 0, 0, 1}));

        instances.add(createInstance(new double[]{1, 1, 0, 0, 1}));
        instances.add(createInstance(new double[]{0, 0, 1, 1, 1}));
        instances.add(createInstance(new double[]{0, 0, 0, 1, 1}));
        instances.add(createInstance(new double[]{0, 0, 0, 1, 1}));
        instances.add(createInstance(new double[]{0, 1, 0, 0, 1}));
//
//		

//		try {
//		associator.root.children.add(new MomentNode(MomentNodeType.INTERMEDIATE, new NominalItem(new Attribute("A", nomVals), 1), associator.root));
//		associator.root.children.add(new MomentNode(MomentNodeType.INTERMEDIATE, new NominalItem(new Attribute("B", nomVals), 1), associator.root));
//		associator.root.children.add(new MomentNode(MomentNodeType.INTERMEDIATE, new NominalItem(new Attribute("C", nomVals), 1), associator.root));
//		associator.root.children.add(new MomentNode(MomentNodeType.INTERMEDIATE, new NominalItem(new Attribute("D", nomVals), 1), associator.root));
//		
//		}catch(Exception exc) {
//			exc.printStackTrace();
//		}
        for (Instance i : instances) {
            associator.addTransaction(i);
        }

        List<Item> items = new ArrayList<Item>();
        try {
            items.add(new NominalItem(new Attribute("A", nomVals), 0));
            //items.add(new NominalItem(new Attribute("C", nomVals), 1));
            //items.add(new NominalItem(new Attribute("D", nomVals), 0));
            //System.out.println("Sup = " + associator.fpRoot.headers.calculateSupport(items));
        } catch (Exception exc) {
            exc.printStackTrace();
        }


        //System.out.println("Sup=" + associator.fpRoot.headers.calculateSupport(items));
        System.out.println(associator.toString());
    }
}
